<template>
  <div class="box">
    <div class="edit-price">
      <input v-model="orderPrice" >
      <div class="submit" @click="update">
        修改价格
      </div>
    </div>
  </div>
</template>

<script>
import { modifyOrderPrice } from "@/api/order";
export default {
  data() {
    return {
      orderPrice: 0,
      routerVal: "",
    };
  },
  onLoad(options) {
    this.routerVal = JSON.parse(decodeURIComponent(options.data));
    this.orderPrice = JSON.parse(decodeURIComponent(options.data)).flowPrice;
  },
  methods: {
    isAmountNumber(value) {
      // 判断是否为数字
      if (isNaN(value)) {
        return false;
      }
      // 判断是否大于0
      if (value <= 0) {
        return false;
      }
      // 判断是否保留两位小数
      if (/^\d+(\.\d{1,2})?$/.test(value.toString())) {
        return true;
      }
      return false;
    },
    // 修改价格
    async update() {
      let isPrice=this.isAmountNumber(this.orderPrice)
      if(!isPrice){
        uni.showToast({
          title:"金额只能是两位小数",
          icon:"none"
        })
        return
      }
      if (this.orderPrice >= 0) {
        uni.showLoading({
          title: "加载中",
          mask: "true",
        });
        let res = await modifyOrderPrice(this.routerVal.sn, {
          orderPrice: this.orderPrice,
        });
        if (res.data.success) {
          uni.showToast({
            title: "修改成功",
            duration: 2000,
            icon: "none",
          });
          setTimeout(() => {
            uni.navigateBack();
          }, 500);
        }
        uni.hideLoading();
      } else {
        uni.showLoading({
          title: "不能小于0",
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  width: 100%;
  height: 100vh;
  // #ifdef H5
  height: calc(100vh - 44px);
  // #endif
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.edit-price {
  margin-top: 30%;
}
/deep/ .u-icon-plus,
/deep/ .u-icon-minus {
  padding: 40rpx;
  width: auto;
  background: #fff !important;
  height: auto !important;
}

/deep/ .u-icon__icon {
  font-size: 50rpx !important;
}

.submit {
  background: #333;
  border-radius: 20rpx;
  height: 80rpx;
  color: #fff;
  font-size: 34rpx;
  text-align: center;
  margin: 180rpx auto 0 auto;
  line-height: 80rpx;
}
input {
 border-bottom: 2rpx solid;
}
</style>